package cn.dnui_zzh807.dnuifood_16110100807.SomethingElse;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import cn.dnui_zzh807.dnuifood_16110100807.R;
import cn.dnui_zzh807.dnuifood_16110100807.bean.ResultBean;
import cn.dnui_zzh807.dnuifood_16110100807.listener.OnRetrofitListener;
import cn.dnui_zzh807.dnuifood_16110100807.model.FoodModel;

public class InsertComments extends AppCompatActivity implements OnRetrofitListener<ResultBean> {
    private Button button;
    private EditText editText;
   private String item_id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_insert_comments);
        item_id=getIntent().getStringExtra("food_id");
        innitView();
        initEvent();


    }

    void initData(){
        FoodModel foodModel = new FoodModel();
         foodModel.insertComment(item_id,editText.getText().toString(),this);
    }

   void initEvent(){
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initData();
            }
        });
   }

    void innitView(){
        editText=findViewById(R.id.insert_content);
        button=findViewById(R.id.content_sure);

    }

    @Override
    public void onSuccess(ResultBean result, int flag) {
        if (result.getSuccess().equals("1")) {
            Toast.makeText(InsertComments.this, "评论成功", Toast.LENGTH_SHORT).show();
            finish();
        }else {
            Toast.makeText(InsertComments.this,"评论失败",Toast.LENGTH_SHORT).show();
        }

    }

    @Override
    public void onFail() {
        Toast.makeText(InsertComments.this,"评论失败",Toast.LENGTH_SHORT).show();
        finish();
    }

}
